package com.qcq.wecheck.result;


import lombok.Data;
import lombok.experimental.Accessors;

/**
 * <p>
 * 公共回复类
 * </p>
 *
 * @author O
 * @version 1.0
 * @since 2018/9/12
 */
@Data
@Accessors(chain = true)
public class CommonResult {
	private final static int SUCCESS_CODE = 200;
	private final static int FAILURE_CODE = 250;
	private final static String SUCCESS_STRING = "请求成功";
	private final static String FAILURE_STRING = "请求失败";

	private int code;
	private boolean success;
	private String message;
	private Object data;

	public static CommonResult success(Object data) {
		CommonResult result = success();
		result.setData(data);
		return result;
	}

	public static CommonResult success() {
		CommonResult result = new CommonResult();
		result.setCode(SUCCESS_CODE);
		result.setSuccess(true);
		result.setMessage(SUCCESS_STRING);
		return result;
	}

	public static CommonResult failure(String message) {
		CommonResult result = failure();
		result.setMessage(message);
		return result;
	}

	public static CommonResult failure() {
		CommonResult result = new CommonResult();
		result.setCode(FAILURE_CODE);
		result.setSuccess(false);
		result.setMessage(FAILURE_STRING);
		return result;
	}
}


